package com.bullsora.kindlerss.model.constraint;

import org.quartz.CronExpression;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.text.ParseException;

/**
 * @author Sorin Buliarca
 */
public class CronValidator implements ConstraintValidator<Cron,String>{
  
  @Override
  public void initialize(Cron constraintAnnotation) {
    
  }

  @Override
  public boolean isValid(String value, ConstraintValidatorContext context) {
    try {
      new CronExpression(value);
    } catch (ParseException e) {
      return false;
    }
    return true;
  }
}
